//
//  IKDownloadTool.h
//  IKFoundation
//
//  Created by Chenxiaocheng on 16/7/20.
//  Copyright © 2016年 inke. All rights reserved.
//

#import <Foundation/Foundation.h>

@class IKDownloader;

typedef NS_ENUM(NSUInteger, IKCacheExpiretime) {
    IKCacheExpiretimeNone     = 0,
    IKCacheExpiretimeTenMin   = 10 * 60,
    IKCacheExpiretimeHalfHour = 30 * 60,
    IKCacheExpiretimeOneHour  = 60 * 60,
    IKCacheExpiretimeDay      = 24 * 60 * 60,
    IKCacheExpiretimeWeek     = 7 * 24 * 60 *60,
    IKCacheExpiretimeForever  = 360 * 24 * 60 * 60,
};

typedef NS_ENUM(NSInteger , IKRequestPriority) {
    IKRequestPriorityLow = -4L,
    IKRequestPriorityDefault = 0,
    IKRequestPriorityHigh = 4,
};


@interface IKDownloadItem : NSObject

/**
 * 资源地址
 */
@property(nonatomic, copy) NSString *url;

/**
 * 存储路径
 */
@property(nonatomic, copy) NSString *filePath;

/**
 * 优先级
 */
@property(nonatomic, assign) IKRequestPriority priority;

//@property(nonatomic, assign) BOOL needCache;

/**
 * 过期时间
 */
//@property(nonatomic, assign) IKCacheExpiretime cacheExpiretime;

@end

@interface IKDownloadInfo : NSObject

@property(nonatomic, assign) int64_t fileSize;       // 文件总长度
@property(nonatomic, assign) int64_t downloadedSize; // 已下载的文件长度

@end


@protocol IKDownloadDelegate <NSObject>

@optional

- (void)Downloader:(IKDownloader *)downloader progress:(int64_t)progress total:(int64_t)total;

- (void)Downloader:(IKDownloader *)downloader code:(NSInteger)code;

@end


@interface IKDownloader : NSObject

@property(nonatomic, readonly, strong) IKDownloadItem *item;
@property(nonatomic, readonly, strong) IKDownloadInfo *info;

@property(nonatomic, weak) id<IKDownloadDelegate> delegate;

- (instancetype)initWithItem:(IKDownloadItem *)item;

- (void)start;

- (void)cancel;

- (float)progress;

@end
